-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rerun: rebuild workflow #180277
rerun: rebuild workflow #180277
Conversation
Perhaps could do with detailing what you are looking to do here. There's a solution here but there's no description of what the problem is. In what scenarios are you needing this and how is GitHub's retry button not suitable for those? It also seems like a lot of copy-pasting (as you've acknowledged). Why do we need all of |
Thanks for having a look @Bo98 - I should have explained a bit further but was just dumping the progress here for now. This is designed to be a replacement for an action that was recently removed, as it sat outside of our organisational scope.
The There was also logic to automatically re-run the suite if certain labels were added, such as |
PR_NUMBER=$(gh pr view "${{ github.event.pull_request.number }}" --json headRefName --jq '.headRefName') | ||
WORKFLOW_RUN_ID=$(gh pr view "${{ github.event.pull_request.number }}" --json headRefName --jq '.headRefName' | xargs -I {} gh run list --workflow=ci.yml --branch={} --json databaseId,status --jq '.[].databaseId') | ||
if [ -n "$WORKFLOW_RUN_ID" ]; then | ||
echo "Rerunning workflow run #$WORKFLOW_RUN_ID for PR #$PR_NUMBER" | ||
gh run rerun "$WORKFLOW_RUN_ID" | ||
else | ||
echo "No runs found for PR #$PR_NUMBER" | ||
fi | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid interpolating right into a shell script, see https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable.
PR_NUMBER=$(gh pr view "${{ github.event.pull_request.number }}" --json headRefName --jq '.headRefName') | |
WORKFLOW_RUN_ID=$(gh pr view "${{ github.event.pull_request.number }}" --json headRefName --jq '.headRefName' | xargs -I {} gh run list --workflow=ci.yml --branch={} --json databaseId,status --jq '.[].databaseId') | |
if [ -n "$WORKFLOW_RUN_ID" ]; then | |
echo "Rerunning workflow run #$WORKFLOW_RUN_ID for PR #$PR_NUMBER" | |
gh run rerun "$WORKFLOW_RUN_ID" | |
else | |
echo "No runs found for PR #$PR_NUMBER" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PR_NUMBER=$(gh pr view "$PULL_REQUEST_NUMBER" --json headRefName --jq '.headRefName') | |
WORKFLOW_RUN_ID=$(gh pr view "$PULL_REQUEST_NUMBER" --json headRefName --jq '.headRefName' | xargs -I {} gh run list --workflow=ci.yml --branch={} --json databaseId,status --jq '.[].databaseId') | |
if [ -n "$WORKFLOW_RUN_ID" ]; then | |
echo "Rerunning workflow run #$WORKFLOW_RUN_ID for PR #$PR_NUMBER" | |
gh run rerun "$WORKFLOW_RUN_ID" | |
else | |
echo "No runs found for PR #$PR_NUMBER" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} |
I also don't really follow what's going on with PR_NUMBER
and WORKFLOW_RUN_ID
. The content of PR_NUMBER
won't be a pull request number, will it?
- completed | ||
pull_request_target: | ||
types: | ||
- closed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need this? I don't think you do anything about closed PRs below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a leftover from the previous workflow that I started with. I will remove it.
- labeled | ||
- unlabeled | ||
schedule: | ||
- cron: '30 */3 * * *' # every 3 hours (30 minutes past the hour) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is run on a schedule, should we also automatically remove some of these labels at some point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Historically, ci-retry
runs until it is removed or CI passes (I just haven't written the logic to remove the label yet). ci-requeue
is removed immediately, but based on the discussion this will likely get removed entirely in lieu of just running using the UI.
types: | ||
- closed | ||
- labeled | ||
- unlabeled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems weird to run this also on unlabeled
events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another carryover from the previous action. If you removed a label such as ci-syntax-only
or ci-skip-install
the suite would automatically be re-run as the current CI state would no longer correlate with the applied labels.
steps: | ||
- name: Re-run CI workflow | ||
run: | | ||
PR_NUMBERS=$(gh pr list -l 'ci-retry' --json number --jq '.[].number') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to use long flags where they're available for readability.
PR_NUMBERS=$(gh pr list -l 'ci-retry' --json number --jq '.[].number') | |
PR_NUMBERS=$(gh pr list --label 'ci-retry' --json number --jq '.[].number') |
This may need to be done elsewhere too.
if: > | ||
github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be cleaner to do something like this:
if: > | |
github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
if: contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event.name) |
if: > | ||
github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if: > | |
github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
if: contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event.name) |
if: > | ||
( | ||
github.event.label.name == 'ci-syntax-only' || | ||
github.event.label.name == 'ci-requeue' || | ||
github.event.label.name == 'ci-skip-install' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if: > | |
( | |
github.event.label.name == 'ci-syntax-only' || | |
github.event.label.name == 'ci-requeue' || | |
github.event.label.name == 'ci-skip-install' | |
) | |
if: contains(fromJSON('["ci-syntax-only", "ci-requeue", "ci-skip-install"]'), github.event.label.name) |
Is there any reason why you wouldn't always do this for |
This is a good suggestion thanks. I think it makes sense to update |
Thanks for the feedback everyone, I think the logic for this is going to be too complicated to build into the action directly, so will require some external functions added in Homebrew/actions. |
This is a start on a workflow to allow scheduled re-running, and triggered re-running of CI suites on PRs.
There's a few things to get sorted before this is ready (if the approach is ok)